﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .ui-jqgrid tr.jqgrow td {
        vertical-align: middle;
        padding: 2px;
    }
</style>
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="syncUserInfo()"><span class="glyphicon glyphicon-cloud-download"></span> 获取用户基本信息</a>
        </div>
        @*<script>$('.toolbar').authorizeButton()</script>*@
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="昵称/手机" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/WeiXinManage/WxUser/GetGridJson",
            height: $(window).height() - 128,
            //rowNum: 20,
            colModel: [
                { label: 'Id', name: 'Id', hidden: true, key: true },
                { label: 'AppId', name: 'AppId', hidden: true },
                { label: 'OpenId', name: 'OpenId', hidden: true },
                {
                    label: '头像', name: 'HeadImgUrl', width: 30, align: 'center', sortable: false,
                    formatter: function (cellvalue) {
                        return '<img alt="image"  height="28" width="28" src="' + cellvalue + '" onerror="this.src=\'/img/image_picture_48px.png\'">';
                    }
                },
                { label: '昵称', name: 'Nickname', width: 100, align: 'center', sortable: false },
                { label: '手机', name: '', width: 100, align: 'center', sortable: false },
                {
                    label: '性别', name: 'Sex', width: 30, align: 'center', sortable: false,
                    formatter: function (cellvalue) {
                        if (cellvalue == 1) return "男";
                        else if (cellvalue == 0) return "女";
                        else return "";
                    }
                },
                { label: '国家', name: 'Country', width: 50, align: 'center', sortable: false },
                { label: '省份', name: 'Province', width: 50, align: 'center', sortable: false },
                { label: '城市', name: 'City', width: 50, align: 'center', sortable: false },
                { label: '语言', name: 'Language', width: 50, align: 'center', sortable: false },
                { label: '关注时间', name: 'SubscribeTime', width: 100, align: 'center', sortable: false },
            ],
            pager: "#gridPager",
            sortname: 'DepartmentId asc,CreatorTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function syncUserInfo() {
        $.modalConfirm("注：只能同步已关注该公众号的用户信息，并且之前没有同步过用户信息，已取消关注的用户无法同步，您确定要同步微信用户信息吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/WeiXinManage/WxUser/SyncUserInfo",
                    param: {},
                    success: function () {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                })
            }
        });
    }
</script>
